var wBox=$("#wbox1").wBox({
	title : "添加频道",
	html : "<span id='add_channel'><form>"+
			   "<table border='1'>"+
				"<tr>"+
					"<td>频道名称</td><td class='input'><input id='name' type='text' maxlength='50'/></td>"+
				"</tr>"+
				"<tr>"+
					"<td>频道位置</td><td class='input'><input id='position' type='text' maxlength='30' /></td>"+
					"</tr>"+
				"<tr>"+
					"<td>频道FTL</td><td class='input'><input id='mould' type='text' maxlength='50' /></td>"+
				"</tr>"+
				"<tr>"+
					"<td>频道html</td><td class='input'><input id='html' type='text' maxlength='50' /></td>"+
				"</tr>"+
				"<tr>"+
					"<td>频道URL</td><td class='input'><input id='url' type='text' maxlength='200' /></td>"+
				"</tr>"+
				"<tr>"+
					"<td style='width:100px;'></td>"+
					"<td class='input'><input type='reset' value='重置'/><input onclick='addChannel()' type='button' value='添加'/></td>"+
				"</tr>"+
			"</table>"+
		"</form></span>"
});

var typeBox=$("#wbox1").wBox({
	title : "书籍类别列表",
	html:"<form action='/control/book/online_addOnline.go'>"+
			   "<table border='1'>"+
				"<tr>"+
					"<td>类型父类</td><td class='input'>${bookType.parent.name}<input id='parentId' type='hidden'/></td>"+
				"</tr>"+
				"<tr>"+
					"<td>类型名称</td><td class='input'><input id='typeName' type='text' maxlength='30' /></td>"+
					"</tr>"+
				"<tr>"+
					"<td>类型备注</td><td class='input'><input id='remark' type='text' maxlength='50'/></td>"+
				"</tr>"+
				"<tr>"+
					"<td style='width:100px;'></td>"+
					"<td class='input'><input type='reset' value='重置'/><input onclick='addBookType()' type='button' value='添加'/></td>"+
				"</tr>"+
			"</table>"+
		"</form>"
});

function addChannel(){
	var name=$("#name").val();
	var position=$("#position").val();
	var mould=$("#mould").val();
	var html=$("#html").val();
	var url=$("#url").val();
	//验证数据
	if($.trim(name).length<1){
		$("#name").addClass("borderStyle");
		return false;
	}else{
		$("#name").removeClass("borderStyle");
	}
	//
	if($.trim(position).length<1){
		$("#position").addClass("borderStyle");
		return false;
	}else{
		$("#position").removeClass("borderStyle");
	}
	//
	if($.trim(mould).length<1){
		$("#mould").addClass("borderStyle");
		return false;
	}else{
		$("#mould").removeClass("borderStyle");
	}
	//
	if($.trim(html).length<1){
		$("#html").addClass("borderStyle");
		return false;
	}else{
		$("#html").removeClass("borderStyle");
	}
	//
	if($.trim(url).length<1){
		$("#url").addClass("borderStyle");
		return false;
	}else{
		$("#url").removeClass("borderStyle");
	}
	//转码
	var urlData="channel.name="+name+"&channel.position="+position+"&channel.mould="+mould+"&channel.html="+html+"&channel.url="+url;
	urlData = encodeURI(encodeURI(urlData));
	
	$.ajax({
	  url: "/control/mapping/channel_add.go",
	  data: urlData,
	  cache: false,
	  success: function(html){
	    $("#add_channel").html(html);
	  }
	});
}
function addBookType(){
	var parentId=$('#parentId').val();
	var typeName=$("#typeName").val();
	var remark=$("#remark").val();
	if($.trim(typeName).length<1){
		$("#typeName").addClass("borderStyle");
		return false;
	}
	//转码
	var urlData="bookType.parent.id="+parentId+"&bookType.name="+typeName+"&bookType.remark="+remark;
	urlData = encodeURI(encodeURI(urlData));
	
	$.ajax({
	  url: "/control/mapping/type_addType.go",
	  data: urlData,
	  cache: false,
	  success: function(html){
	    $("#main_content").html(html);
	    $.closePopupLayer();
	  }
	});
}
function editType(){
	_typeid=$("#type_id").val();
	_typeparentid=$("#type_parent_id").val();
	_typename=$("#type_name").val();
	_typeremark=$("#type_remark").val();
	if($.trim(_typename).length<1){
		$("#type_name").addClass("borderStyle");
		return false;
	}
	if($.trim(_typeremark).length<1){
		$("#type_remark").addClass("borderStyle");
		return false;
	}
	//转码
	var urlData="bookType.parent.id="+_typeparentid+"&bookType.id="+_typeid+"&bookType.name="+_typename+"&bookType.remark="+_typeremark;
	urlData = encodeURI(encodeURI(urlData));
	
	$.ajax({
	  url: "/control/mapping/type_editName.go",
	  data: urlData,
	  cache: false,
	  success: function(html){
	    $("#main_content").html(html);
	    $.closePopupLayer();
	  }
	});
}
/**
 * 修改书籍类型的名称
 */
var bookId=undefined;
var bookName=undefined;
function setValue(key,value){
	bookId=key;
	bookName=value;
}

function test(){
	var urlPath="";
	if(bookId==undefined && bookName==undefined){
		bookId = $("#book_type_id").val();
		bookName = $("#book_type_name").val();
		urlPath="/control/mapping/type_typeUI.go?bookType.parent.id="+null+"&bookType.parent.name="+null;
	}else{
		urlPath = "/control/mapping/type_typeUI.go?bookType.parent.id="+bookId+"&bookType.parent.name="+encodeURI(encodeURI(bookName));
	}
	$.openPopupLayer({
		name: "mySecondPopup",
		width: 300,
		height: 300,
		url: urlPath
	});
}
/*修改书籍类型*/
function editNameUI(typeid,parentid,name,remark){
	var urlPath= "/control/mapping/type_editNameUI.go?bookType.id="+typeid+
			"&bookType.parent.id="+parentid+"&bookType.name="+name+"&bookType.remark="+remark;
	urlPath = encodeURI(encodeURI(urlPath));
	$.openPopupLayer({
		name: "mySecondPopup",
		width: 300,
		height: 300,
		url: urlPath
	});
}
/**选择权限的父类**/
function selectPowerParent(){
	var urlPath="/control/mapping/power_powerParent.go";
	$.openPopupLayer({
		name: "mySecondPopup",
		width: 300,
		height: 300,
		url: urlPath
	});
}
/**
 * 书籍审核
 */
function auditingBook(bookid){
	var urlPath="/control/mapping/book_auditingUI.go?book.id="+bookid;
	$.openPopupLayer({
		name: "mySecondPopup",
		width: 300,
		height: 300,
		url: urlPath
	});
}
/**
 * 生成搜索索引
 * @return
 */
function search(){
	$.ajax({
		  url: "/control/mapping/search_initApp.go",
		  data: "",
		  cache: false,
		  success: function(html){
		    $("#main_content").html(html);
		  }
	});
}